#include<bits/stdc++.h>
using namespace std;
#define ERROR 0
#define OK 1
typedef int Status;
typedef struct DNode{
	int data;
	int freq;
	DNode *next;
	DNode *pre;	
}DNode, *DLinkList;
Status Init(DLinkList &L)
{
	L = new DNode;
	if(!L) return ERROR;
	L->next = NULL;
	L->pre = NULL;
	return OK;
}
Status Create(DLinkList &L, int n)
{
	DNode *t = L;
	for(int i = 0; i < n; i ++)
	{
		DNode *p = new DNode;
		cin >> p->data;
		p->freq = 0;
		t->next = p;
		p->pre = t;
		t = p;
	}
	t->next = NULL;
}
void Locate(DLinkList &L, int x)
{
	/***************Begin********************/
    DNode *cur = L->next;
	while(cur && cur->data != x) cur = cur->next;
	cur->freq++;

	if(cur->next) cur->next->pre = cur->pre;
	cur->pre->next = cur->next;
	
	DNode *p = cur->pre;
	while(p != L && p->freq <= cur->freq) p = p->pre;
	// 把cur插到p的后面
	cur->next = p->next;
	cur->pre = p;
	p->next->pre = cur;
	p->next = cur;
    /***************End**********************/
}
void Show(DLinkList L)
{
	DNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ' << p->freq << endl;
		p = p->next;
	}
	cout << endl;
}
int main()
{
	DLinkList L;
	Init(L);
	
	int n;
	cin >> n;
	Create(L, n);
 	
 	int w;
 	cin >> w;
 	while(w --)
 	{
 		int x;
		cin >> x;
		Locate(L, x);	
	}
 	Show(L);	
	return 0; 
}